package so.hands.xam.utils; 

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

/** 
 * @Title: FileTools.java  
 * @Package so.hands.xam.utils 
 * @Description: TODO(添加描述) 
 * @author 朱晓峰 
 * @date 2012-11-3 下午08:17:40 
 * @version V1.0 
 */

public class FileTools{
	
	private String fileContent;
	private File file;
	
	public FileTools(String pathname) {
		this.file = new File(pathname);  		    
	}

	
	/**  
	 * @Title: getFileToString  
	 * @Description: 读取文件并以String类型返回文件内容，换行符"\n"
	 * @return String
	 * @param @throws IOException 
	 * @return String 
	 * @throws IOException 
	 */
	public String getFileToString() throws IOException{
		FileInputStream inputstream = new FileInputStream(this.file);
		StringBuffer buffer = new StringBuffer();
		BufferedReader bufferreader = new BufferedReader(new InputStreamReader(inputstream));
		String line;
		line = bufferreader.readLine(); // 读取第一行
		while (line != null) { // 如果 line 为空说明读完了
			buffer.append(line); // 将读到的内容添加到 buffer 中
			buffer.append("\n"); // 添加换行符
			line = bufferreader.readLine(); // 读取下一行
		}
		inputstream.close();
		return this.setFileContent(buffer.toString());
	}

	public String setFileContent(String fileContent) {
		  
		        this.fileContent = fileContent;  
		    
		return fileContent;
	}

	public String getFileContent() {
		  
		        return fileContent;  
		    
	}
	
	
}
  
    